// Make a namespace.
if (typeof Samplerbox == 'undefined') {
  var Samplerbox = {};
}

/**
 * Controller for pane.xul
 */
Samplerbox.DaftPunk = {

onLoad: function() {
    var presets = document.getElementById("presets");
    var daftmenu = document.createElement("menuitem");
    daftmenu.setAttribute("label","Daft Punk");
    daftmenu.setAttribute("value","daftpunk");
    daftmenu.setAttribute("oncommand","Samplerbox.DaftPunk.preset_daftpunk('low')");
    presets.appendChild(daftmenu);
    var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch2);
    var custompref = pref.getCharPref("extensions.samplerbox.currentpreset");
    if (custompref == "daftpunk") {
    Samplerbox.DaftPunk.addpitchbox();
    Samplerbox.DaftPunk.preset_daftpunk();
    }
},

  addpitchbox: function() {
    var customhbox = document.getElementById("custom");
    var lowbox     = document.createElement("button");
    var highbox    = document.createElement("button");
    var labelpitch = document.createElement("label");
    lowbox.setAttribute("label","Low");
    lowbox.setAttribute("oncommand","Samplerbox.DaftPunk.preset_daftpunk('low')");
    lowbox.setAttribute("class","button-dark");
    highbox.setAttribute("label","High");
    highbox.setAttribute("oncommand","Samplerbox.DaftPunk.preset_daftpunk('high')");
    highbox.setAttribute("class","button-dark");
    labelpitch.setAttribute("value","Pitch Bending :");
    customhbox.appendChild(labelpitch);
    customhbox.appendChild(lowbox);
    customhbox.appendChild(highbox);
  },

  preset_daftpunk: function(pitch) {
  
  var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch2);
  var custompref = pref.getCharPref("extensions.samplerbox.currentpreset");
  if (custompref != "daftpunk") {
  Samplerbox.DaftPunk.addpitchbox();
  pref.setCharPref("extensions.samplerbox.currentpreset","daftpunk");
  }
  
  //Here you can modify the sounds file
  var sound1  = '01-work_it.wav';
  var sound2  = '02-make_it.wav';
  var sound3  = '03-do_it.wav';
  var sound4  = '04-make_us.wav';
  var sound5  = '05-harder.wav';
  var sound6  = '06-better.wav';
  var sound7  = '07-faster.wav';
  var sound8  = '08-stronger.wav';
  var sound9  = '09-more_than.wav';
  var sound10 = '10-hour.wav';
  var sound11 = '11-our.wav';
  var sound12 = '12-never.wav';
  var sound13 = '13-ever.wav';
  var sound14 = '14-after.wav';
  var sound15 = '15-work_is.wav';
  var sound16 = '16-over.wav';
  
  //Here you can modify the sounds name
  var soundname1  = "Work it";
  var soundname2  = "Make it";
  var soundname3  = "Do it";
  var soundname4  = "Make us";
  var soundname5  = "Harder";
  var soundname6  = "Better"
  var soundname7  = "Faster"
  var soundname8  = "Stronger"
  var soundname9  = "More than"
  var soundname10 = "Hour"
  var soundname11 = "Our"
  var soundname12 = "Never"
  var soundname13 = "Ever"
  var soundname14 = "After"
  var soundname15 = "Work is"
  var soundname16 = "Over"
  
  if (navigator.platform == "Win32") {
  var slash = "\\"; }
  else {
  var slash = "/"; }
  var file = Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager).getInstallLocation('DaftPunkSamplerBox@geekshadow.com').getItemLocation('DaftPunkSamplerBox@geekshadow.com'); 
      pref.setCharPref("extensions.samplerbox.sound1", file.path + slash + 'sounds' + slash + pitch + slash + sound1);
      pref.setCharPref("extensions.samplerbox.sound2", file.path + slash + 'sounds' + slash + pitch + slash + sound2);
      pref.setCharPref("extensions.samplerbox.sound3", file.path + slash + 'sounds' + slash + pitch + slash + sound3);
      pref.setCharPref("extensions.samplerbox.sound4", file.path + slash + 'sounds' + slash + pitch + slash + sound4);
      pref.setCharPref("extensions.samplerbox.sound5", file.path + slash + 'sounds' + slash + pitch + slash + sound5);
      pref.setCharPref("extensions.samplerbox.sound6", file.path + slash + 'sounds' + slash + pitch + slash + sound6);
      pref.setCharPref("extensions.samplerbox.sound7", file.path + slash + 'sounds' + slash + pitch + slash + sound7);
      pref.setCharPref("extensions.samplerbox.sound8", file.path + slash + 'sounds' + slash + pitch + slash + sound8);
      pref.setCharPref("extensions.samplerbox.sound9", file.path + slash + 'sounds' + slash + pitch + slash + sound9);
      pref.setCharPref("extensions.samplerbox.sound10", file.path + slash + 'sounds' + slash + pitch + slash + sound10);
      pref.setCharPref("extensions.samplerbox.sound11", file.path + slash + 'sounds' + slash + pitch + slash + sound11);
      pref.setCharPref("extensions.samplerbox.sound12", file.path + slash + 'sounds' + slash + pitch + slash + sound12);
      pref.setCharPref("extensions.samplerbox.sound13", file.path + slash + 'sounds' + slash + pitch + slash + sound13);
      pref.setCharPref("extensions.samplerbox.sound14", file.path + slash + 'sounds' + slash + pitch + slash + sound14);
      pref.setCharPref("extensions.samplerbox.sound15", file.path + slash + 'sounds' + slash + pitch + slash + sound15);
      pref.setCharPref("extensions.samplerbox.sound16", file.path + slash + 'sounds' + slash + pitch + slash + sound16);
      pref.setCharPref("extensions.samplerbox.name1", soundname1);
      pref.setCharPref("extensions.samplerbox.name2", soundname2);
      pref.setCharPref("extensions.samplerbox.name3", soundname3);
      pref.setCharPref("extensions.samplerbox.name4", soundname4);
      pref.setCharPref("extensions.samplerbox.name5", soundname5);
      pref.setCharPref("extensions.samplerbox.name6", soundname6);
      pref.setCharPref("extensions.samplerbox.name7", soundname7);
      pref.setCharPref("extensions.samplerbox.name8", soundname8);
      pref.setCharPref("extensions.samplerbox.name9", soundname9);
      pref.setCharPref("extensions.samplerbox.name10", soundname10);
      pref.setCharPref("extensions.samplerbox.name11", soundname11);
      pref.setCharPref("extensions.samplerbox.name12", soundname12);
      pref.setCharPref("extensions.samplerbox.name13", soundname13);
      pref.setCharPref("extensions.samplerbox.name14", soundname14);
      pref.setCharPref("extensions.samplerbox.name15", soundname15);
      pref.setCharPref("extensions.samplerbox.name16", soundname16);
      document.getElementById("sound-file1").label = soundname1;
      document.getElementById("sound-file2").label = soundname2;
      document.getElementById("sound-file3").label = soundname3;
      document.getElementById("sound-file4").label = soundname4;
      document.getElementById("sound-file5").label = soundname5;
      document.getElementById("sound-file6").label = soundname6;
      document.getElementById("sound-file7").label = soundname7;
      document.getElementById("sound-file8").label = soundname8;
      document.getElementById("sound-file9").label = soundname9;
      document.getElementById("sound-file10").label = soundname10;
      document.getElementById("sound-file11").label = soundname11;
      document.getElementById("sound-file12").label = soundname12;
      document.getElementById("sound-file13").label = soundname13;
      document.getElementById("sound-file14").label = soundname14;
      document.getElementById("sound-file15").label = soundname15;
      return document.getElementById("sound-file16").label = soundname16;
			},
};
window.addEventListener("load", function(e) { Samplerbox.DaftPunk.onLoad(e); }, false);			